/* File: assign_geruso.do
 * Author: Jacob Klimek, Yunjuan Liu, Luca Maini
 * Purpose: assign geruso status. Needs the variables:
 * 				1. universalstatus
 *				2. PA_ST
 *
 * Date Created: 03/19/2021
 *
 */

capture confirm variable universalstatus
if _rc != 0 display "variable universalstatus not found"

capture confirm variable PA_ST
if _rc != 0 display "variable PA_ST not found"


gen geruso = .

* Not covered
replace geruso = 1 if ///
	universalstatus == "NOT COVERED DRUGS TIER":universalstatuslbl | ///
	universalstatus == "UNKNOWN COVERAGE":universalstatuslbl

* Medical
replace geruso = 3 if universalstatus == "MEDICAL":universalstatuslbl

* Non-Preferred Specialty
replace geruso = 4 if ///
	universalstatus == "INJECTABLE DRUGS TIER":universalstatuslbl | ///
	universalstatus == "NON-PREFERRED SPECIALTY DRUGS TIER":universalstatuslbl | ///
	universalstatus == "SPECIALTY DRUGS TIER":universalstatuslbl

* Preferred Specialty
replace geruso = 5 if ///
	universalstatus == "PREFERRED SPECIALTY DRUGS TIER":universalstatuslbl

* Covered/non-preferred brands 
replace geruso = 6 if ///
	universalstatus == "COVERED DRUGS TIER":universalstatuslbl | ///
	universalstatus == "NON-PREFERRED BRAND DRUGS TIER":universalstatuslbl | ///
	universalstatus == "NON-PREFERRED GENERICS AND NON-PREFERRED BRANDS":universalstatuslbl

* Preferred brands (combining generic/generic preferred with preferred brand
* as we shouldn't really have generic classifications)
replace geruso = 7 if ///
	universalstatus == "GENERIC DRUGS TIER":universalstatuslbl | ///
	universalstatus == "NON-PREFERRED GENERIC DRUGS TIER":universalstatuslbl | ///
	universalstatus == "NON-PREFERRED GENERICS AND PREFERRED BRANDS":universalstatuslbl | ///
	universalstatus == "PREFERRED BRAND DRUGS TIER":universalstatuslbl | ///
	universalstatus == "PREFERRED GENERIC DRUGS TIER":universalstatuslbl | ///
	universalstatus == "PREFERRED GENERICS AND PREFERRED BRANDS":universalstatuslbl | ///
	universalstatus == "VALUE BRAND DRUGS TIER":universalstatuslbl | ///
	universalstatus == "VALUE GENERIC DRUGS TIER":universalstatuslbl | ///
	universalstatus == "ZERO CO-PAY TIER":universalstatuslbl

* Add indicator for nonpreferred tier (before it gets overridden by the PA_ST 
* indicator)
gen nonpreferred = geruso >= 3 & geruso <= 6

replace geruso = 2 if PA_ST == 1

* check that all values are populated
count if geruso == .
if r(N) > 0 disp "some values of geruso are missing"

* 	Label
label define gerlbl 1 "NOT COVERED" 			///
					2 "RESTRICTED (PA/ST)"		///
					3 "MEDICAL"					///
					4 "NON-PREFERRED SPECIALTY"	///
					5 "PREFERRED SPECIALTY"		///
					6 "NON-PREFERRED BRAND"		///
					7 "PREFERRED BRAND"
label values geruso gerlbl
